package java9_21;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Test_3 {
    public static void main(String[] args) throws UnknownHostException {
        InetAddress inetAddress=InetAddress.getLocalHost();//获取本机地址对象
        System.out.println("主机名"+inetAddress.getHostName());
        System.out.println("主机地址"+inetAddress.getHostAddress());
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        InetAddress[]arr=InetAddress.getAllByName("www.sina.com");
        for (InetAddress address : arr) {
            System.out.println("主机名"+address.getHostName());
            System.out.println("主机地址"+address.getHostAddress());
        }
    }
}
